package com.sophialex.health.record.common.draw;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

public class UIFormAttachment {

	private FormAttachment top;

	private FormAttachment bottom;

	private FormAttachment left;

	private FormAttachment right;

	private Control control;

	public UIFormAttachment(Control control) {
		this.control = control;
	}

	public UIFormAttachment() {

	}

	public FormAttachment getTop() {
		return top;
	}

	public void setTop(FormAttachment top) {
		this.top = top;
	}

	public FormAttachment getBottom() {
		return bottom;
	}

	public void setBottom(FormAttachment bottom) {
		this.bottom = bottom;
	}

	public FormAttachment getLeft() {
		return left;
	}

	public void setLeft(FormAttachment left) {
		this.left = left;
	}

	public FormAttachment getRight() {
		return right;
	}

	public void setRight(FormAttachment right) {
		this.right = right;
	}

	public static UIFormAttachment getDefault(Control control, int topHeight, int bottomHeight, boolean isOne) {
		UIFormAttachment defaultAttachement = new UIFormAttachment(control);
		FormAttachment top;
		FormAttachment bottom;
		FormAttachment left;
		FormAttachment right;
		if(isOne) {
			top = new FormAttachment(control, topHeight);
			// bottom = new FormAttachment(0, bottomHeight);
			left = new FormAttachment(control, 0, SWT.LEFT);
			right = new FormAttachment(100, -10);
		} else {
			top = new FormAttachment(control, topHeight);
			// bottom = new FormAttachment(control, bottomHeight, SWT.BOTTOM);
			left = new FormAttachment(control, 0, SWT.LEFT);
			right = new FormAttachment(control, 0, SWT.RIGHT);
		}

		// FormAttachment top = new FormAttachment(control,20);
		// FormAttachment bottom = new FormAttachment(0,180);
		// FormAttachment left = new FormAttachment(control,0,SWT.LEFT);
		// FormAttachment right = new FormAttachment(100,-10);
		defaultAttachement.setTop(top);
		// defaultAttachement.setBottom(bottom);
		defaultAttachement.setLeft(left);
		defaultAttachement.setRight(right);
		return defaultAttachement;
	}

	public static UIFormAttachment getDefault(Control control, int topHeight, int bottomHeight) {
		return getDefault(control, topHeight, bottomHeight, false);

	}

	public static UIFormAttachment getDefault(int topHeight) {
		UIFormAttachment defaultAttachement = new UIFormAttachment();
		FormAttachment top;
		FormAttachment left;
		FormAttachment right;
		top = new FormAttachment(0, topHeight);
		left = new FormAttachment(2,0);
		right = new FormAttachment(100, -10);
		defaultAttachement.setTop(top);
		defaultAttachement.setLeft(left);
		defaultAttachement.setRight(right);
		return defaultAttachement;
	}
}
